<template>
	<view class="content">
		<!-- 个人信息区域 -->
		<view class="myinfo">
			<view class="myinfo_header">
				<image :src="userInfo.avatar"></image>
				<view class="myinfo_item">
					<view class="item_thumbsup">
						<text>获赞</text>
						<view>{{userInfo.thumbsNum}}</view>
					</view>
					<view class="item_focus">
						<text>关注</text>
						<view>{{userInfo.contactNum}}</view>
					</view>
					<view class="item_fans">
						<text>粉丝</text>
						<view>{{userInfo.fansNum}}</view>
					</view>
				</view>
			</view>
			<view class="myinfo_footer">
				<text>{{$store.getters.getUser.username}}</text>
				<view class="myinfo_settings" @click="clickSettings">
					<i class="iconfont icon-cebianlan" style="font-size: 50rpx;"></i>
					<u-popup :show="show" mode="right" customStyle="width: 500rpx;">
						<view >
							<view class="popup_title">
								<text>设置</text>
							</view>
							<u-cell-group>
								<u-cell title="个人基本信息" isLink url="../userInfo/userInfo"></u-cell>
								<u-cell title="关于广东美食" isLink url="../about/about"></u-cell>
								<view style="background-color: #f6f5ec; height: 20rpx;">
								</view>
								<u-cell title="切换账号" isLink url="../userLogin/userLogin" customStyle="text-align:center"></u-cell>
								<view class="popup_exit">
									<text @click="exit">退出程序</text>
								</view>
							</u-cell-group>
						</view>
					</u-popup>
				</view>
			</view>
		</view>

		<!-- 笔记收藏区域 -->
		<view class="note-collect">
			<view class="nc_title">
				<text @click="clickNote" :class="{activeStyle:isNote}">笔记</text>
				<text @click="clickCollection" :class="{activeStyle:!isNote}">收藏</text>
			</view>
			<view class="note_content" v-show="isNote">
				<note-box :noteInfo="noteInfo"></note-box>
			</view>
			<view class="collect_content" v-show="!isNote">
				<note-box :noteInfo="collectionInfo" ></note-box>
			</view>
		</view>
	</view>
</template>

<script>
	import noteBox from '../../components/noteBox/note_box.vue';
	export default {
		components:{
			noteBox
		},
		data() {
			return {
				show: false,
				closeable: true,
				isNote:true,
				userInfo:[],
				noteInfo:[],
				collectionInfo:[],
				uid:'',
			}
		},
		onLoad() {
		//	this.uid = uni.getStorageSync("token")
			// this.showInfo(),
			// this.showNote(),
			// this.showCollection()
		},
		onShow(){
		    this.showInfo()
			this.showNote(),
			this.showCollection()
		},
		methods: {
			clickSettings() {
				uni.$u.sleep().then(() => {
					this.show = !this.show
				})
			},
			showInfo(){
				uni.request({
					url: 'http://localhost:8081/user/getUserById',
					method: 'GET',
					data: {
						id: uni.getStorageSync("token")
					},
					success: (res) => {
						if (res.data.state == 200) {
							this.userInfo = res.data.data
						}
					}
				});
			},
			showNote(){
				uni.request({
					url: 'http://localhost:8081/note/getNoteById?id='+uni.getStorageSync("token"),
					method: 'GET',
					// data: {
					// 	region:"广州"
					// },
					success: (res) => {
						//if (res.data.state == 200) {
							this.noteInfo=res.data
					//	}
					}
				});
			},
			showCollection(){
				let collectNote = []
				uni.request({
					url: 'http://localhost:8081/user/getCollection?id='+uni.getStorageSync("token"),
					method: 'GET',
					success: (res) => {
						//if (res.data.state == 200) {
							for(let n=0;n<res.data.length;n++){
								collectNote.push(res.data[n].notes)
							//	this.collectNoteId.push(res.data[n].cn_id)
							}	
							this.collectionInfo = collectNote
					//	}
					}
				});
			},
			clickNote(){
				this.isNote=true
				if(this.noteInfo==""){
					this.showNote()
				}
			},
			clickCollection(){
				this.isNote=false
				if(this.collectionInfo==""){
					this.showCollection()
				}
			},
			exit(){
				uni.removeStorageSync("token")
				uni.redirectTo({
				    url: '../userLogin/userLogin'
				});
			}
		}
	}
</script>

<style lang="scss">
	.content {
		.myinfo {
			width: 750rpx;
			height: 380rpx;
			background-image: linear-gradient(to top, #d1fdff 0%, #cde6c7 100%);

			.myinfo_header {
				width: 100%;
				display: flex;
				padding: 10rpx 40rpx;

				image {
					width: 160rpx;
					height: 160rpx;
					border-radius: 120rpx;
				}

				.myinfo_item {
					width: 60%;
					display: flex;
					text-align: center;
					justify-content: space-around;
					align-items: center;
				}
			}

			.myinfo_footer {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 10rpx 40rpx;

				text {
					font-size: 45rpx;
				}
				.popup_title{
					background-color: #cde6c7; 
					height: 100rpx;
					line-height: 100rpx;
					text-align: center;
				}
				.popup_exit{
					width: 100%;
					position:fixed;
					bottom:0;
					padding: 15rpx 0;
					background-color: #f3f3ea;
					text{
						margin: 0 160rpx;
						font-size: 40rpx;
					}
				}

			}
		}

		.nc_title {
			width: 750rpx;
			height: 80rpx;
			background-color: #cde6c7;
			border-radius: 30rpx 30rpx 0 0;
			margin-top: -40rpx;
			text-align: center;
			line-height: 80rpx;

			text {
				margin: 0 60rpx;
				
			}
			.activeStyle{
				border-bottom: 2px solid red;
			}
		}
	}
</style>
